package com.sunchangming.myweb;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.api.client.auth.oauth2.Credential;


public class GetFileServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7940139750825385383L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Credential cred=Auth.getAuthFlow().loadCredential("daemon");
		if(cred==null)
			response.sendError(503);
		else {
			String filename=request.getParameter("f");
			String url=String.format("https://apis.live.net/v5.0/%s/content?suppress_redirects=true&access_token=%s&suppress_redirects=true", filename,cred.getAccessToken());
			response.sendRedirect(url);
		}
	}
}
